<!DOCTYPE html>
<html>
	<head>
	 
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>用户注册</title>
		<link rel="shortcut icon" type="image/x-icon" href="../image/logo.png" />
		<link rel="stylesheet"  type="text/css" href="../layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="../css/register.css" />
	</head>
	<body>
		<div class="head">  
			<div class="logo">
				<img src="../image/logo.png" />
			</div>
			 
			
			<div class="login">
				<img src="../image/login02.png" />
			</div>
			
			<div class="login-text">
				 
				<form class="yc-login">
					<ul>
						
						<li class="yc-tel">								 
							<input  type="text" name="mtel" id="u_phone" v-model="mtel" placeholder="请输入手机号" @blur="finds()" />
						</li>
						<li class="yc-pwd">
							 
							<input id="u_pwd" type="password" name="mpwd"  v-model="mpwd" placeholder="请输入密码" />
						</li>
						<li class="yc-pwd">
							 
							<input type="password" name="mpwd"  v-model="mpwd" placeholder="确认密码" />
						</li>
						<li class="yc-yz">
							 
							<input type="yanzhengma"  id="logsafecode"  placeholder="验证码" />

							<input type="button" id="safecodeloginimg" onclick="createCode()"  style="width:70px;height: 25px;" title='点击更换验证码' />


							<a id="safecodeloginlink" class="tips" href="#" onclick="createCode()">看不清？换一张</a>
						</li>
						 
						 
						<li>
							<a id="button" class="yc-btn" href="javascript:void(0)"  onclick="validate()" >注册</a>
						</li>
						<li class="yc-tishi">
							<input type="radio" checked="checked"/>
							 我已阅读并同意<a href="#">《数码用户服务协议》</a><a href="#">《隐私政策》</a> 
						</li>
						
						  
						 
					</ul>
					
				</form>
			</div>
			
			
		</div>
		
		
		
		
	</body>

	<script type="text/javascript" src="../js/jquery-3.4.1.min.js"></script>
	<script src="js/ajax.js"></script>
	<script src="../layui/layui.js"></script>
	<script>

		$(function () {
			createCode();
		});

		var flog=false;


		$("#button").click(function () {


			let u_phone = $("#u_phone").val();
			let u_pwd = $("#u_pwd").val();

			if(flog== true) {


				$.ajax({

					url: '../user',
					dataType: 'json',

					secureuri: false,
					data: {
						op: 'adduser', u_phone: u_phone, u_pwd: u_pwd
					},
					success: function (rs) {
						if (rs > 0) {
							window.location.href = 'login.html';
						} else {
							alert('注册失败');
						}

					},
					error: function (rs) {
						alert('注册失败');

					}


				});
			}


		});


		var code ; //在全局定义验证码

		function createCode(){
			code = "";
			var codeLength = 4;//验证码的长度
			var checkCode = document.getElementById("safecodeloginimg");
			var random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',
					'S','T','U','V','W','X','Y','Z');//随机数
			for(var i = 0; i < codeLength; i++) {//循环操作
				var index = Math.floor(Math.random()*36);//取得随机数的索引（0~35）
				code += random[index];//根据索引取得随机数加到code上
			}
			checkCode.value = code;//把code值赋给验证码
		}
		//校验验证码
		function validate(){


			var inputCode = document.getElementById("logsafecode").value.toUpperCase(); //取得输入的验证码并转化为大写
			if(inputCode.length <= 0) { //若输入的验证码长度为0
				alert("请输入验证码！"); //则弹出请输入验证码
			}else if(inputCode != code ) { //若输入的验证码与产生的验证码不一致时
				alert("验证码输入错误！@_@"); //则弹出验证码输入错误
				createCode();//刷新验证码
				document.getElementById("input").value = "";//清空文本框
			}else { //输入正确时

				flog = true;
			}
		}




	</script>



</html>
